<?php
/**
 * Administration Main Screen
 * This page display on the left a menu and on the right the content
 * of the page.
 * All administration point are reacheable from this page
 * 
 * @author Xavier VILAIN
 * @package Hive\Admin
 * @license #license-hive#
 */
use Fox\Authorization;
use Fox\Html\Wrapper;
use Fox\Core\Errors;
use Fox\Generator;
use Fox\Html\Navigation\Menu\Item;
use Fox\Html\Navigation\Menu\Item\Sub;
use Fox\Html\Navigation\Menu;

$xview = Xview::instance();
if(!Authorization\Manager::check(Hive\Customizing::AUTH_ADMIN)) {
	$xview->accessDenied();
}

$defaultPage = 'process';
// Main Config
$page = Xview::instance()->val('page','users-list');
$customizing = Hive\Admin\Customizing::instance();
$master = 'admin';
$action = 'main';

$wrapper = new Wrapper('leftCol');
// Users
$usersMenu = new Menu('users-menu',Msg(Hive::BUNDLE,Hive::MENU_USERS));
// Users List
$usersMenu->add(new Item('admin-users-list',Msg(Hive::BUNDLE,Hive::MENU_USERS_LIST),
						Generator::url($master,'users','list'),null,'users'));
// Add a new User
$usersMenu->add(new Item('admin-users-add',Msg(Hive::BUNDLE,Hive::MENU_USER_ADD),
						Generator::url($master,'users','add'),null,'user-add'));
// Handle Contact Groups
$usersMenu->add(new Item('users-groups',Msg(Hive::BUNDLE,Hive::MENU_USER_GROUPS),
						Generator::url('users','groups'),null,'user-group'));
$wrapper->add($usersMenu);

// -------- Contact Menu --------------
$contactsMenu = new Menu('contacts',Msg(Hive::BUNDLE,Hive::MENU_CONTACTS));
// Education Level
$contactsMenu->add(new Item('education-levels',Msg(Hive::BUNDLE,Hive::MENU_EDUCATION_LEVEL),
						Generator::url('education','levels'),null,'diploma'));
// Statuses
$contactsMenu->add(new Item('contacts-statuses',Msg(Hive::BUNDLE,Hive::MENU_CONTACT_STATUSES),
						Generator::url('contacts','statuses'),null,'status'));
// Sources
$contactsMenu->add(new Item('contacts-sources',Msg(Hive::BUNDLE,Hive::MENU_CONTACT_INCOMINGS),
						Generator::url('contacts','sources'),null,'source'));
// Countries
$contactsMenu->add(new Item('contacts-countries',Msg(Hive::BUNDLE,Hive::MENU_CONTACT_COUNTRIES),
						Generator::url('contacts','countries'),null,'country'));
// Merge 
$contactsMenu->add(new Item('contacts-wishes-admin',Msg(Hive::BUNDLE,Hive::TITLE_WISHES),
						Generator::url('contacts','wishes','admin'),null,'wishes'));
// Entretiens
$contactsMenu->add(new Item('contacts-interviews-admin',Msg(Hive::BUNDLE,Hive::TITLE_INTERVIEWS),
						Generator::url('contacts','interviews','admin'),null,'interviews'));
// Merge 
$contactsMenu->add(new Item('contacts-tools-merge',Msg(Hive::BUNDLE,Hive::MERGE),
						Generator::url('contacts','tools','merge'),null,'merge'));
$wrapper->add($contactsMenu);

// Job & Missions Menu					
$missionsMenu = new Menu('missions',Msg(Hive::BUNDLE,Hive::MENU_MISSIONS));
// Handle Mission Types
$missionsMenu->add(new Item('missions-types',Msg(Hive::BUNDLE,Hive::MENU_MISSION_TYPES),
						Generator::url('missions','types'),null,'type'));
// Handle Mission Workflows
$missionsMenu->add(new Item('missions-workflows',Msg(Hive::BUNDLE,Hive::MISSION_WORKFLOWS),
						Generator::url('missions','workflows'),null,'workflow'));
// Handle Mission Job Boards
$missionsMenu->add(new Item('missions-boards',Msg(Hive::BUNDLE,Hive::MISSION_JOB_BOARDS),
						Generator::url('missions','boards'),null,'job-board'));
$wrapper->add($missionsMenu);						
// Cross Application
$crossApplicationMenu = new Menu('crossApplication',Msg(Hive::BUNDLE,Hive::CROSS_APPLICATION));
// Currencies
$crossApplicationMenu->add(new Item('admin-currencies',Msg(Hive::BUNDLE,Hive::CURRENCIES),
						Generator::url('admin','currencies'),null,'currency'));
$wrapper->add($crossApplicationMenu);

if(isset($_GET['uri']) && !empty($_GET['uri']))
{
	$parts = explode('-', $_GET['uri']);
	if(count($parts) > 2) {
		$url = Generator::url($parts[0],$parts[1],$parts[2]);
	} else {
		$url = Generator::url($parts[0],$parts[1]);
	}
	if(!Xview::instance()->isModule($url)) {
		$url = null;
	}
}
if(empty($url))
{
	$params = array('return' => true);
	list($url,$page) = $customizing->defaultSummaryPage($params);
}

$item = $wrapper->item($page);
if(empty($item)) {
	$page = Xview::instance()->val('page','users-list');
	$item = $wrapper->item($page);
}
if(!empty($item)) {
	$item->selected();
}

$edit = '<div id="leftColContainer">
			<div id="leftCol">
			<div id="pagelet_welcome_box">
				<div class="hive-missions-box">
				</div>
			</div>
			<div id="pagelet_navigation">
				<div class="uiFutureSideNav">
				'.$wrapper->render().'
			</div>
		</div>
		</div>';
?>
<div id="leftColContainer" >
	<div id="leftCol">
		<div id="pagelet_welcome_box">
			<div class="hive-contact-box">
				<div class="clearfix uiImageBlock fbxWelcomeBox">
					<div class="uiImageBlockContent" >
						<span class="title"></span>
						<div class="i"></div>
					</div>
				</div>			
			</div>
		</div>
		<div id="pagelet_navigation">
			<div class="uiFutureSideNav">
			<?php echo $wrapper->render(); ?>
			</div>
		</div>
	</div>
</div>
<div id="contentCol" class="hasLeftCol" style="padding-left: 5px; padding-top: 5px; ">
	<?php echo Xview::instance()->display($url); ?>
</div>